﻿using System;
using System.Windows.Threading;

namespace Wp7Tools.ViewServices {
    public class TimerService : ITimerService {
        private Action _tick;
        private DispatcherTimer _timer;

        public TimeSpan Interval { get; set; }

        public TimerService() {
            _timer = new DispatcherTimer();
        }

        public void Start(Action tick) {
            _tick = tick;
            _timer.Interval = Interval;
            _timer.Tick -= TimerTick;
            _timer.Tick += TimerTick;
            _timer.Start();
        }

        public void Stop() {
            _timer.Tick -= TimerTick;
            _timer.Stop();
        }

        private void TimerTick(object sender, EventArgs e) {
            _tick.Invoke();
        }
    }
}